<template>
  <div class="edit">
    <div class="editcon">
      <div class="title">{{editTitle || '编辑'}}</div>
      <div class="inputcon">
        <textarea id="textarea" v-model="txt" cols="30" rows="14"></textarea>
      </div>
      <div class="e-btn">
        <div @click="emit('close')" class="cancel">取消</div>
        <div @click="emit('confirm',txt)" class="confirm">确定</div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref, watch, nextTick } from "vue";

const emit = defineEmits(["close","confirm"]);

const props = defineProps({
  defaultTxt:String,
  editTitle:String
})
let parseContent = (content)=> {
  const lineBreakPattern = /<br\s*\/?>/gi; // 匹配 <br> 或 <br/> 或 <br />
  const spacePattern = /&nbsp;/gi; // 匹配 &nbsp;

  const parsedText = content
  .replace(lineBreakPattern, '\n')
  .replace(spacePattern, ' ');

  return parsedText;
}

let txt = ref(parseContent(props.defaultTxt))


onMounted(() => {
  nextTick(() => {
  })
})


</script>

<style lang="scss" scoped>
.edit {
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.6);
  .editcon{
    position: absolute;
    transform: translate(-50%,-50%);
    top: 50%;
    left: 50%;
    width: 950px;
    min-height: 300px;
    border: 1px solid rgba(65, 141, 255,0.15);
    border-radius: 8px;
    background: #0a101c;
    .title {
      color: #fff;
      padding: 12px 0;
      font-size: 20px;
      margin-top: -1px;
      font-weight: bold;
      font-style: italic;
      letter-spacing: 2px;
      background: url('/images/ctitbg.png') no-repeat;
      background-size: 100% 100%;
      text-align: center;
    }
    .inputcon{
      padding: 20px;
      >textarea{
        width: 100%;
        height: 100%;
        background: #151a2c;
        border: none;
        padding: 10px;
        color: #fff;
        line-height: 1.5;
        letter-spacing: 2px;
      }
    }
    .e-btn{
      color: #fff;
      display: flex;
      justify-content: flex-end;
      margin-right: 20px;
      margin-bottom: 20px;
      >div{
        padding: 10px 30px;
        font-style: italic;
        cursor: pointer;
        letter-spacing: 2px;
        margin-left: 10px;
      }
      .cancel{
        background: #1b2338;
        border: 1px solid #303d5d;
      }
      .confirm{
        background: #0f46aa;
        border: 1px solid #0574e5;
      }
    }
  }
}
</style>